package com.altuure.yablog.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;


public class PopulateListener implements ApplicationListener{
    private DataPopulator dataPopulator;
    private boolean once=true;
    
    public void onApplicationEvent(ApplicationEvent event) {
        System.out.println("event = " + event);
        if ((event instanceof ContextRefreshedEvent)&& once) {
            dataPopulator.populate();
            once=false;
            
        }
     
        
    }
    @Autowired
    public void setDataPopulator(DataPopulator dataPopulator) {
        this.dataPopulator = dataPopulator;
    }
}
